package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目")
public class NursingProjectController extends BaseController {
    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    public ResponseResult<PageResponse<NursingProjectVo>> getAllNursingProject(String name, Integer pageNum, Integer pageSize,Integer status) {
        Integer page = pageNum == null ? 1 : pageNum;
        System.out.println("name:"+name+",page:"+page+",pageSize:"+pageSize+",status:"+status);
        return success(nursingProjectService.getAllNursingProject(name, page, pageSize,status));
    }

    @PostMapping
    public ResponseResult addNursingProject(@RequestBody NursingProjectDto nursingProjectDto) {
        System.out.println("nursingProjectDto:"+nursingProjectDto);
        nursingProjectService.addNursingProject(nursingProjectDto);
        return success();
    }

    @GetMapping("/{id}")
    public ResponseResult<NursingProjectVo> getById(@PathVariable Integer id) {
        return success(nursingProjectService.selectById(id));
    }

    @PutMapping("/{id}")
    public ResponseResult updateNursingProject(@RequestBody NursingProjectDto nursingProjectDto) {
        System.out.println("\n\n\n\n\nursingProjectDto:"+nursingProjectDto);
        nursingProjectService.updateNursingProject(nursingProjectDto);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateNursingProjectStatus(@PathVariable Integer id, @PathVariable Integer status) {
        nursingProjectService.enableOrDisable(id, status);
        return success();
    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteNursingProject(@PathVariable Integer id) {
        nursingProjectService.deleteNursingProject(id);
        return success();
    }

    @GetMapping("all")
    public ResponseResult<List<NursingProjectVo>> getAll(){
//        List<NursingProjectVo> list = nursingProjectService.getAll();
        return success();
    }
}
